//-----------------------------------------------------------------------
// <copyright file="PresencePropertyCollection.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace Microsoft.Live.Messenger
{
    using System;
    using System.Collections;
    using Microsoft.Live.Core;

    /// <summary>
    /// Represents a presence property collection.
    /// </summary>
    public class PresencePropertyCollection : Collection
    {
        internal PresencePropertyCollection(object obj)
            : base(obj, null)
        {
        }

        /// <summary>
        /// Gets the <c>PresenceProperty</c> by name.
        /// </summary>
        /// <param name="name">The name of the <c>PresenceProperty</c>.</param>
        /// <returns>The <c>PresenceProperty</c> if it exists, otherwise <c>null</c>.</returns>
        public PresenceProperty this[string name]
        {
            get
            {
                object obj = this.Entity.GetItem(name);
                if (obj == null)
                {
                    return null;
                }

                return (PresenceProperty)this.FindOrCreate(new MessengerEntity(obj));
            }
        }

        internal override object FindOrCreate(MessengerEntity entity)
        {
            return new PresenceProperty(
                entity.GetProperty<string>("Name"),
                entity.GetProperty<string>("Value"));
        }
    }
}